#include <iostream>
#include <fstream>
#include <time.h>

#include "Reader.h"

const int numberOfCycles = 500;

int main(int argc, char* argv[])
{
    FILE* isF;
    std::ifstream is;
    int i;
    time_t startTime;
    time_t endTime;
    char buffer[100];
	
    isF = fopen("InputFile.txt", "r");
    if (0 != isF)
    {
        time(&startTime);
        for (i = 0; i < numberOfCycles; ++i)
        {
            while (0 == feof(isF))
            {
                readChar(isF);
            }
            clearerr(isF);
            fseek(isF, 0, SEEK_SET);
        }
        time(&endTime);
        fclose(isF);
    }
    std::cout << "Character time (FILE*)   = " << (endTime - startTime) << std::endl;

    isF = fopen("InputFile.txt", "r");
    if (0 != isF)
    {
        time(&startTime);
        for (i = 0; i < numberOfCycles; ++i)
        {
            while (0 == feof(isF))
            {
                readString(isF);
            }
            clearerr(isF);
            fseek(isF, 0, SEEK_SET);
        }
        time(&endTime);
        fclose(isF);
    }
    std::cout << "String time (FILE*)      = " << (endTime - startTime) << std::endl;


    is.open("InputFile.txt");
    if (true == is.is_open())
    {
        time(&startTime);
        for (i = 0; i < numberOfCycles; ++i)
        {
            while (false == is.eof())
            {
                readChar(is);
            }
            is.clear();
            is.seekg(0, std::ios_base::beg);
        }
        time(&endTime);
        is.close();
    }
    std::cout << "Character time (istream) = " << (endTime - startTime) << std::endl;

    is.open("InputFile.txt");
    if (true == is.is_open())
    {
        time(&startTime);
        for (i = 0; i < numberOfCycles; ++i)
        {
            while (false == is.eof())
            {
                readString(is);
            }
            is.clear();
            is.seekg(0, std::ios_base::beg);
        }
        time(&endTime);
        is.close();
    }
    std::cout << "String time (istream)    = " << (endTime - startTime) << std::endl;

    return 0;
}